package mysql

import (
	"ETikTok/models"
	"database/sql"
	"go.uber.org/zap"
)

func GetTagList() (tagList []*models.Tag, err error) {
	sqlStr := `select tag_id, tag_name from tag`
	if err = db.Select(&tagList, sqlStr); err != nil {
		if err == sql.ErrNoRows {
			zap.L().Warn("there is no tag in the db")
			err = nil
		}
	}
	return
}

// GetTagDetailByID 根据社区ID查询社区详情
func GetTagDetailByID(id int64) (tag *models.TagDetail, err error) {
	tag = new(models.TagDetail)
	sqlStr := `select tag_id, tag_name, introduction, create_time  
		from tag 
		where tag_id = ?
		`
	if err = db.Get(tag, sqlStr, id); err != nil {
		zap.L().Error("GetTagDetailByID failed", zap.Error(err))
		if err == sql.ErrNoRows {
			err = ErrorInvalidID
		}
	}
	return tag, err
}
